package com.laicunba.ext.web.controller.console.sys;

import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.laicunba.ext.service.SlaveJzhReportService;
import com.laicunba.ext.web.controller.BaseController;
import com.laicunba.service.exception.MyException;

@Controller
@RequestMapping(value = "/console/ext/sys")
public class JzhReportController extends BaseController {

	@Autowired
	private SlaveJzhReportService jzhReportService;

	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping(value = "/jzhInvestorCreateReport.htm")
	public String jzhInvestorCreateReport(String mobile) {
		JSONObject json = new JSONObject();
		try {

			SlaveJzhReportService.Result result = jzhReportService.reportInvestor(1000);
			json.put("fileCount", result.getFileCount());
			json.put("TotalRows", result.getTotalRows());
		} catch (MyException e) {
			json.put("code", e.getCode());
			return json.toJSONString();
		}

		return json.toJSONString();
	}

	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping(value = "/jzhBorrowerCreateReport.htm")
	public String jzhBorrowerCreateReport(String mobile) {
		JSONObject json = new JSONObject();
		try {

			SlaveJzhReportService.Result result = jzhReportService.reportBorrower(1000);
			json.put("fileCount", result.getFileCount());
			json.put("TotalRows", result.getTotalRows());
		} catch (MyException e) {
			json.put("code", e.getCode());
			return json.toJSONString();
		}

		return json.toJSONString();
	}

	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping(value = "/jzhBidFreezenReport.htm")
	public String jzhBidReport(String mobile) {
		JSONObject json = new JSONObject();
		try {

			SlaveJzhReportService.Result result = jzhReportService.reportBidFreezen(1000);
			json.put("fileCount", result.getFileCount());
			json.put("TotalRows", result.getTotalRows());
		} catch (MyException e) {
			json.put("code", e.getCode());
			return json.toJSONString();
		}

		return json.toJSONString();
	}

	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping(value = "/jzhRepaymentReport.htm")
	public String jzhRepaymentReport(String mobile) {
		JSONObject json = new JSONObject();
		try {

			SlaveJzhReportService.Result result = jzhReportService.reportRepayment(1000);
			json.put("fileCount", result.getFileCount());
			json.put("TotalRows", result.getTotalRows());
		} catch (MyException e) {
			json.put("code", e.getCode());
			return json.toJSONString();
		}

		return json.toJSONString();
	}

	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping(value = "/jzhCreateBidWithBidOrderReport.htm")
	public String jzhCreateBidWithBidOrderReport(String mobile) {
		JSONObject json = new JSONObject();
		try {

			SlaveJzhReportService.Result result = jzhReportService.reportBid(1000);
			json.put("fileCount", result.getFileCount());
			json.put("TotalRows", result.getTotalRows());
		} catch (MyException e) {
			json.put("code", e.getCode());
			return json.toJSONString();
		}

		return json.toJSONString();
	}

	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping(value = "/jzhFinancingTargetReport.htm")
	public String jzhFinancingTargetReport(String mobile) {
		JSONObject json = new JSONObject();
		try {

			SlaveJzhReportService.Result result = jzhReportService.reportFinancingTarget(1000);
			json.put("fileCount", result.getFileCount());
			json.put("TotalRows", result.getTotalRows());
		} catch (MyException e) {
			json.put("code", e.getCode());
			return json.toJSONString();
		}

		return json.toJSONString();
	}
}
